package com.cleaningcloud.cld.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cleaningcloud.common.log.annotation.Log;
import com.cleaningcloud.common.log.enums.BusinessType;
import com.cleaningcloud.common.security.annotation.RequiresPermissions;
import com.cleaningcloud.cld.domain.CldCheckIndicator;
import com.cleaningcloud.cld.service.ICldCheckIndicatorService;
import com.cleaningcloud.common.core.web.controller.BaseController;
import com.cleaningcloud.common.core.web.domain.AjaxResult;
import com.cleaningcloud.common.core.utils.poi.ExcelUtil;
import com.cleaningcloud.common.core.web.page.TableDataInfo;

/**
 * 指标库Controller
 * 
 * @author cleaningcloud
 * @date 2024-10-12
 */
@RestController
@RequestMapping("/checkIndicator")
public class CldCheckIndicatorController extends BaseController
{
    @Autowired
    private ICldCheckIndicatorService cldCheckIndicatorService;

    /**
     * 查询指标库列表
     */
    @RequiresPermissions("cld:checkIndicator:list")
    @GetMapping("/list")
    public TableDataInfo list(CldCheckIndicator cldCheckIndicator)
    {
        startPage();
        List<CldCheckIndicator> list = cldCheckIndicatorService.selectCldCheckIndicatorList(cldCheckIndicator);
        return getDataTable(list);
    }

    /**
     * 导出指标库列表
     */
    @RequiresPermissions("cld:checkIndicator:export")
    @Log(title = "指标库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CldCheckIndicator cldCheckIndicator)
    {
        List<CldCheckIndicator> list = cldCheckIndicatorService.selectCldCheckIndicatorList(cldCheckIndicator);
        ExcelUtil<CldCheckIndicator> util = new ExcelUtil<CldCheckIndicator>(CldCheckIndicator.class);
        util.exportExcel(response, list, "指标库数据");
    }

    /**
     * 获取指标库详细信息
     */
    @RequiresPermissions("cld:checkIndicator:query")
    @GetMapping(value = "/{indicatorId}")
    public AjaxResult getInfo(@PathVariable("indicatorId") Long indicatorId)
    {
        return success(cldCheckIndicatorService.selectCldCheckIndicatorByIndicatorId(indicatorId));
    }

    /**
     * 新增指标库
     */
    @RequiresPermissions("cld:checkIndicator:add")
    @Log(title = "指标库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CldCheckIndicator cldCheckIndicator)
    {
        return toAjax(cldCheckIndicatorService.insertCldCheckIndicator(cldCheckIndicator));
    }

    /**
     * 修改指标库
     */
    @RequiresPermissions("cld:checkIndicator:edit")
    @Log(title = "指标库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CldCheckIndicator cldCheckIndicator)
    {
        return toAjax(cldCheckIndicatorService.updateCldCheckIndicator(cldCheckIndicator));
    }

    /**
     * 删除指标库
     */
    @RequiresPermissions("cld:checkIndicator:remove")
    @Log(title = "指标库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{indicatorIds}")
    public AjaxResult remove(@PathVariable Long[] indicatorIds)
    {
        return toAjax(cldCheckIndicatorService.deleteCldCheckIndicatorByIndicatorIds(indicatorIds));
    }
}
